home *** CD-ROM | disk | FTP | other *** search
/ CDUTIL 13 / CDUTIL #13 Julio 1995.iso / windows / acadcom / ads / sample / template.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-08  |  5.0 KB  |  155 lines

  1. /*    
  2.  
  3.    TEMPLATE.C
  4.  
  5.    Copyright (C) 1990, 1991, 1992, 1993, 1994 by Autodesk, Inc.
  6.  
  7.    Permission to use, copy, modify, and distribute this software in 
  8.    object code form for any purpose and without fee is hereby granted, 
  9.    provided that the above copyright notice appears in all copies and 
  10.    that both that copyright notice and the limited warranty and 
  11.    restricted rights notice below appear in all supporting 
  12.    documentation.
  13.  
  14.    AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.  
  15.    AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF 
  16.    MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC.
  17.    DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE 
  18.    UNINTERRUPTED OR ERROR FREE.
  19.  
  20.    Use, duplication, or disclosure by the U.S. Government is subject to 
  21.    restrictions set forth in FAR 52.227-19 (Commercial Computer 
  22.    Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) 
  23.    (Rights in Technical Data and Computer Software), as applicable.
  24.     
  25.    .
  26.  
  27.       DESCRIPTION:
  28.   
  29.       This is a template file to demonstrate the structure required by      
  30.       an ADS application.
  31.   
  32.       Prototype for ADS application.
  33.    
  34.       by Amy Berger       
  35.       April 16, 1990
  36.   
  37.       Updated July 30, 1990
  38.   
  39. */
  40.  
  41.  
  42. #include  <stdio.h>
  43. #include  "adslib.h"
  44.  
  45. static int loadfuncs();
  46. int adsfunc();
  47.  
  48.  
  49. /* MAIN - the main routine */
  50.  
  51.  
  52. void
  53. main(argc, argv)
  54.   int argc;
  55.   char *argv[];
  56. {
  57.     int stat;
  58.     short scode = RSRSLT;             /* This is the default result code */
  59.  
  60.     ads_init(argc, argv);             /* Initialize the interface */
  61.  
  62.     for ( ;; ) {                      /* Note loop conditions */
  63.  
  64.         if ((stat = ads_link(scode)) < 0) {
  65.  
  66.             printf("TEMPLATE: bad status from ads_link() = %d\n", stat);
  67.  
  68.             /* Can't use ads_printf to display 
  69.                this message, because the link failed */
  70.             fflush(stdout);
  71.             exit(1);
  72.         }
  73.  
  74.         scode = RSRSLT;               /* Default return value */
  75.  
  76.         /* Check for the following cases here */
  77.         switch (stat) {
  78.  
  79.         case RQXLOAD:                 /* Register your ADS external functions.
  80.                                          Register your function handlers if you
  81.                                          want your ADS functions to be called
  82.                                          transparent to this dispatch loop.
  83.                                          Required for all applications.  */
  84.  
  85.             scode = loadfuncs() ? RSRSLT : RSERR;
  86.             break;
  87.  
  88.         case RQSUBR:                  /* This case is normally expanded to 
  89.                                          select one of the application's 
  90.                                          external functions */
  91.             break;
  92.  
  93.         case RQXUNLD:                 /* Do C program cleanup here.
  94.                                          Not required unless you need to
  95.                                          clean up your own allocated resources.
  96.  
  97.                                          Note: You don't have to undefine ADS
  98.                                          functions.  LISP does it for you.  */
  99.             break;
  100.  
  101.         case RQSAVE:                  /* AutoCAD SAVE command notification.
  102.                                          You can use it for your own database
  103.                                          synchronization.  Not required.  */
  104.             break;
  105.  
  106.         case RQQUIT:                  /* AutoCAD QUIT command notification.
  107.                                          Not required.  */
  108.             break;
  109.  
  110.         case RQEND:                   /* AutoCAD END command notification.
  111.                                          Not required.  */
  112.             break;
  113.  
  114.         default:
  115.             break;
  116.         }
  117.     }
  118. }
  119.  
  120.  
  121. /* LOADFUNCS  --  Define external functions with AutoLISP.
  122.  
  123.                   Normally expanded to call ads_defun() once for each
  124.                   external function to be defined, assigning each one a
  125.                   different ADS function code.  ads_regfunc() is then
  126.                   called to specify the handler function for each ADS
  127.                   function code.
  128. */
  129. static int loadfuncs()
  130. {
  131.     if (ads_defun("ADSFUNC", 0) == RTNORM) {   /* Define function */
  132.         ads_regfunc(adsfunc, 0);      /* Register handler */
  133.         return 1;
  134.     } else
  135.         return 0;
  136. }
  137.  
  138.  
  139. /* ADSFUNC  --  Sample handler for ADS function code 0.
  140.  
  141.                 This function will handle (ADSFUNC) calls.  You can have
  142.                 one handler for each external function, or use one handler
  143.                 for several functions.  ads_getfuncode() tells the handler
  144.                 which function (ADS function code) it's dealing with.
  145.  
  146.                 If you choose to use the RQSUBR method, you should place
  147.                 this function call following the RQSUBR switch statement.
  148. */
  149. int adsfunc()
  150. {
  151.     /* Do something. */
  152.  
  153.     return RSRSLT;                    /* Normal completion */
  154. }
  155.